package test;

import java.util.concurrent.CountDownLatch;

public class demo14 {
    CountDownLatch latch = new CountDownLatch(10);
    private static int count = 0;
    Runnable runnable = () -> {
        try {
            System.out.println(count++);
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        latch.countDown();
    };
    public static void main(String[] args) throws InterruptedException {
        demo14  test = new demo14();
        for(int i = 0; i < 10; i++) {
            new Thread(test.runnable).start();
        }
        test.latch.await();
        System.out.println("计数器减为零，线程执行完毕");
    }
}
